﻿/**
*DialogTipView class
*auth:lww
*version:1.0
*date:2014-10-11
*/
function DialogTipView(context) {
    this.id = "";
    this.name = "DialogTipView";
    this.version = "1.0.0";
    this.mContext = context;
    this.mLayoutParams = null;
    this.mViewObject = null;
    this.contentViewObject = null;
    this.isRoundCorner = true;
    /**
    *info
    */
    this.mTitleBar = null;
    this.mInfoView = null;
    this.mButtonBar = null;
    this.titleText = "";
    this.infoText = "";
    this.mWdith = 320;
    this.mHeight = 280;
    this.infoClassName = "tipDialogView";
}

DialogTipView.prototype.setWidth = function (w) {
    this.mWdith = w;
};

DialogTipView.prototype.getWidth = function () {
    return this.mWdith;
};

DialogTipView.prototype.setHeight = function (h) {
    this.mHeight = h;
};

DialogTipView.prototype.getHeight = function () {
    return this.mHeight;
};

DialogTipView.prototype.invalidate = function () {
    if (this.mViewObject == null) {
        this.mViewObject = new LinearLayout(this.mContext);
    }
    if (this.mLayoutParams == null) {
        this.mLayoutParams = new LayoutParams(MATCH_PARENT, MATCH_PARENT);
    }
    this.mViewObject.setLayoutParams(this.mLayoutParams);
    return this.mViewObject.view();
};

DialogTipView.prototype.view = function () {
    return this.invalidate();
};

DialogTipView.prototype.getDragView = function () {
    if (this.mTitleBar != null) {
        return this.mTitleBar.view();
    }
    return null;
};

DialogTipView.prototype.getId = function () {
    if (this.id == null || this.id == "") {
        this.id = id();
    }
    return this.id;
};

DialogTipView.prototype.setId = function (ids) {
    this.id = ids;
};

DialogTipView.prototype.createTipInfo = function () {
    if (this.mTitleBar == null) {
        this.mTitleBar = new LinearLayout(this.mContext);
        this.mTitleBar.setLayoutParams(new LayoutParams(MATCH_PARENT, 26));
        this.mTitleBar.setBackground(new Drawable(DefaultBgColor, null));
        this.mTitleBar.addChildView(formatHtmlIco(DefaultIcoInfo, "18px", "18px", "4px 0 0 4px", this.titleText));
        this.mTitleBar.addChildView(formatHtmlString(this.titleText, "#fff", "12px", "bold", "5px 0 0 2px"));       
        this.mInfoView = new LinearLayout(this.mContext);
        this.mInfoView.setLayoutParams(new LayoutParams(MATCH_PARENT, 60));
        this.mInfoView.setBackground(new Drawable("#ffffff", null));             
        this.mInfoView.setView(setCss($cc("div", this.infoText), this.infoClassName));
        this.mButtonBar = new LinearLayout(this.mContext);
        this.mButtonBar.setLayoutParams(new LayoutParams(MATCH_PARENT, 40));
        this.mButtonBar.setBackground(new Drawable("#ffffff", null));
        this.mButtonBar.setGrative("center");
        var okBtn = createInput("button", "确定", "60px", "28px", "", "确定", "center");
        var o = this; okBtn.onclick = function () {
            o.onViewEvent(o,ButtonEventOk);
        };
        this.mButtonBar.addChildView(okBtn);
        if (this.mViewObject == null) {
            this.invalidate();
        }
        if (this.isRoundCorner) {
            this.mViewObject.setClassName("color1");
            for (var i = 1; i < 5; i++) {
                var bt = $c("b", id()); 
                bt.className = "b" + i.toString();
                this.mViewObject.addChildView(bt);
            }
            this.contentViewObject = new LinearLayout(this.mContext);
            this.contentViewObject.setLayoutParams(new LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
            this.contentViewObject.setClassName("content");
            this.mViewObject.addChildView(this.contentViewObject.view());
            for (i = 5; i < 9; i++) {
                var bb = $c("b", id()); 
                bb.className = "b" + i.toString();
                this.mViewObject.addChildView(bb);
            }
            this.contentViewObject.addChildView(this.mTitleBar.view());
            this.contentViewObject.addChildView(this.mInfoView.view());
            this.contentViewObject.addChildView(this.mButtonBar.view());
        }
        else {
            this.mViewObject.addChildView(this.mTitleBar.view());
            this.mViewObject.addChildView(this.mInfoView.view());
            this.mViewObject.addChildView(this.mButtonBar.view());
        }
    }
    else {
        this.mTitleBar.setInnerHTML(this.titleText);
        this.mInfoView.setInnerHTML(this.infoText);
    }
};

DialogTipView.prototype.setTipInfo = function (title, info) {
    this.titleText = title;
    this.infoText = info;
    this.createTipInfo();
};

DialogTipView.prototype.onClose = function (refObj, type) {
    //set to your callback:close interface   
};

DialogTipView.prototype.onViewEvent = function (refObj, type) {
    this.onClose(refObj,type);
};

markscript("DialogTipView");
//end DialogTipView.js